package com.microstation.service.impl;

import java.util.List;

import com.microstation.enums.ResultEnum;
import com.microstation.exception.ElementEmptyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.microstation.service.QuesInfoService;
import com.microstation.dao.QuesInfoDao;
import com.microstation.common.Assist;
import com.microstation.common.Result;
import com.microstation.entity.po.QuesInfo;

/**
 * QuesInfo的服务接口的实现类
 *
 * @author
 */
@Service
public class QuesInfoServiceImpl implements QuesInfoService {
    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private QuesInfoDao quesInfoDao;

    @Override
    public Result find(QuesInfo quesInfo, Assist assist) {
        long results = quesInfoDao.getQuesInfoRowCount(quesInfo);
        List<QuesInfo> result = quesInfoDao.selectQuesInfo(quesInfo, assist);
        return new Result(results, result);
    }

    @Override
    public QuesInfo findOne(Long id) {
        if (id == null) {
            return null;
        }
        QuesInfo result = quesInfoDao.selectQuesInfoById(id);
        return result;
    }

    @Override
    public Integer saveNotNull(QuesInfo value) {
        if (value == null) {
            return null;
        }
        if (value.getActId() == null) {
            throw new ElementEmptyException(ResultEnum.EMPTY.getInfo());
        }
        int result = quesInfoDao.insertNotNullQuesInfo(value);
        return result;
    }

    @Override
    public Integer updateNotNullById(QuesInfo value) {
        if (value == null) {
            return null;
        }
        int result = quesInfoDao.updateNotNullQuesInfoById(value);
        return result;
    }

    @Override
    public Integer deleteById(Long id) {
        if (id == null) {
            return null;
        }
        int result = quesInfoDao.deleteQuesInfoById(id);
        return result;
    }

    @Override
    public List<QuesInfo> findList(QuesInfo quesInfo, Assist assist) {
        return quesInfoDao.selectQuesInfo(quesInfo, assist);
    }
}